$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		bissedit();
	}
});
function bissedit() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/itm/project/bissupdatetwo",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			paytypeId : {
				required : true
			}
		},
		messages : {
			paytypeId : {
				required : icon + "请选择付款方式"
			}
		}
	})
}

function deviceAmount() {
	var deviceAmount = Number($("input[ name='deviceAmountTwoDO.deviceAmount']").val());
	var installAmount = Number($("input[ name='deviceAmountTwoDO.installAmount']").val());
	var techAmount = Number($("input[ name='deviceAmountTwoDO.techAmount']").val());
	var conOtherAmount = Number($("input[ name='deviceAmountTwoDO.conOtherAmount']").val());

	var compPurPrice = Number($("input[ name='deviceAmountTwoDO.compPurPrice']").val());
	var onPurPrice = Number($("input[ name='deviceAmountTwoDO.onPurPrice']").val());
	var otherPrice = Number($("input[ name='deviceAmountTwoDO.otherPrice']").val());

	var outlayPrice = Number($("input[ name='deviceAmountTwoDO.outlayPrice']").val());
	var insurancePrice = Number($("input[ name='deviceAmountTwoDO.insurancePrice']").val());
	var outlayOtherPrice = Number($("input[ name='deviceAmountTwoDO.outlayOtherPrice']").val());

	var taxCost = Number($("input[ name='deviceAmountTwoDO.taxCost']").val());
	var financialCosts = Number($("input[ name='deviceAmountTwoDO.financialCosts']").val());
	var otherCost = Number($("input[ name='deviceAmountTwoDO.otherCost']").val());

	var saleExpPrice = Number($("input[ name='deviceAmountTwoDO.saleExpPrice']").val());
	var travelPrice = Number($("input[ name='deviceAmountTwoDO.travelPrice']").val());
	var businessPrice = Number($("input[ name='deviceAmountTwoDO.businessPrice']").val());
	var mgrPrice = Number($("input[ name='deviceAmountTwoDO.mgrPrice']").val());
	var onofficePrice = Number($("input[ name='deviceAmountTwoDO.onofficePrice']").val());
	var expressPrice = Number($("input[ name='deviceAmountTwoDO.expressPrice']").val());
	var mgrOtherPrice = Number($("input[ name='deviceAmountTwoDO.mgrOtherPrice']").val());

	var dataadd = deviceAmount+installAmount+techAmount+conOtherAmount;
	var datdel = compPurPrice+onPurPrice+otherPrice+outlayPrice+insurancePrice+outlayOtherPrice+
		saleExpPrice+travelPrice+businessPrice+mgrPrice+onofficePrice+expressPrice+mgrOtherPrice+taxCost+financialCosts+otherCost;
	var data = dataadd-datdel;
	console.log(dataadd);
	console.log(datdel);
	data = data.toFixed(2);
	$("#allCost").val(datdel)
	$("#profit").val(data)
	var aaa = data/dataadd*100
	aaa = aaa.toFixed(2);
	$("#profitmargin").val((aaa)+"%")
}